#{extends 'main.html'/}
<div class="l-clear"></div>
<div id="maingrid" style="margin-top:1px"></div> <br />
<div style="display:none;"></div>
<div id="approvedgrid" style="margin-top:1px"></div> <br />
<div style="display:none;"></div>

<div id="detail" style="display:none;"><form id="mainform" method="post"></form></div>
<div id="comment" style="display:none;"><form id="commentform" method="post"></form></div>

<script type="text/javascript">  
    $(function () {
        var manager, grid, approvedgrid; 
        function f_initGrid()
        {
              
            grid = manager = $("#maingrid").ligerGrid({
                columns: [
                    { display: '时间', name: 'noteDate', width: 80, type: 'textarea' },
                    { display: '姓名', name: 'realName', width: 80,  type: 'textarea' },
                    { display: '科室', name: 'deptName', width: 80,  type: 'textarea' },
                    { display: '考评类别', name: 'categoryName', width: 80, type: 'textarea' },
                    { display: '项目', name: 'checkTitle', width: 150, type: 'textarea' },
                    { display: '内容', name: 'content', width: 200, type: 'textarea' },
                    { display: '物品', name: 'goods', width:80, type: 'textarea' },
                    { display: '分数', name: 'score', width:50, type: 'textarea' }, 
                    { display: '填报人', name: 'createdManName', width:60, type: 'textarea' },
                    { display: '状态', name: 'approveLevelName', width: 120, type: 'textarea' }
                   // ,{ display: '备注', name: 'approveComment', width: 100, type: 'textarea' }
                ],
                url: "approvejson?level="+level+'&isapprove=0', method: "GET", title: "未审核的填报档案",	            
                width: '100%',height:"59%", pageSize: 20, showTitle: true, checkbox: true, checkboxColWidth: 5,              
                toolbar: { items: [
                        { text: '查看', click: viewRow, icon: 'bluebook' },   
                        { line: true },      
                        { text: '审核通过', click: confirmRow, icon: 'ok' },
                        { line: true }, 
                        { text: '退回', click: cancelRow, icon: 'modify' },
                        { line: true },
                        { text: '批量审核', click: multiRow, icon: 'ok' },                 
                        { line: true }
                      
                    ] }
            });
         	
            approvedgrid=$("#approvedgrid").ligerGrid({
                columns: [
                    { display: '时间', name: 'noteDate', width: 80, type: 'textarea' },
                    { display: '姓名', name: 'realName', width: 80,  type: 'textarea' },
                    { display: '科室', name: 'deptName', width: 80,  type: 'textarea' },
                    { display: '考评类别', name: 'categoryName', width: 80, type: 'textarea' },      
                    { display: '项目', name: 'checkTitle', width: 100, type: 'textarea' },    
                    { display: '内容', name: 'content', width: 200, type: 'textarea' },
                    { display: '物品', name: 'goods', width:80, type: 'textarea' },
                    { display: '分数', name: 'score', width:50, type: 'textarea' }, 
                    { display: '填报人', name: 'createdManName', width:60, type: 'textarea' },
                    { display: '状态', name: 'approveLevelName', width: 120, type: 'textarea' }
                   // ,{ display: '备注', name: 'approveComment', width: 100, type: 'textarea' }
                ],
                url: "approvejson?level="+level2+'&isapprove=1', method: "GET", title: "已审核的填报档案",	            
                width: '100%', pageSize: 20,
                toolbar: { items: [
                        { text: '导出', click: exporexcel, icon: 'outbox' },   
                        { line: true }   
                    ] }
                
            });
        }
        
        f_initGrid();
        //导出已审核的医德档案
        function exporexcel(approvedgrid){
            location.href ="expor_approve_excel/?approvelevel="+ level2+'&isapprove=1';
        }
      
        function f_reload() {
            grid.loadData();
        }
        function app_reload() {
            approvedgrid.loadData();
        }
        
        function getSelected()
        { 
            var row = manager.getSelectedRow();
            if (!row) { alert('请选择行'); return; }
            alert(JSON.stringify(row));
        }
        
        function getData()
        { 
            var data = manager.getData();
            alert(JSON.stringify(data));
        }
        //查看
        function viewRow()
        { 
            var selected = grid.getSelected();
            if (!selected) { LG.tip('请选择行!'); return }    
            
            showDetailWindow({
                id: selected.id,
                noteDate: selected.noteDate,  
                realName:selected.realName,
                deptName:selected.deptName,
                content:selected.content,
                certifyMan:selected.certifyMan,
                checkListId:selected.checkId,
                checkListtitle:selected.checkTitle,
                category:selected.category             
            }, false);
          
        }
        
        function modifyRow()
        {         
            var selected = grid.getSelected();
            if (!selected) { LG.tip('请选择行!'); return }
            
            var parent = grid.getParent(selected);
           
            showDetail({   
                checkListId: selected.id,                
                checkListtitle: selected.title                  
            }, false);
        }
        
        function deleteRow()
        {
            jQuery.ligerDialog.confirm('确定删除吗?', function (confirm) {
                if (confirm) f_delete(); });
        }
        
        function f_delete() 
        {
            var selected = grid.getSelected();
            if (selected) {
                $.ajax({
                    url: 'checklist/' + selected.id,
                    type: 'DELETE',                  
                    loading: '正在删除中...',                  
                    success: function () {
                        //LG.showSuccess('删除成功');
                        LG.tip('删除成功!');
                        f_reload();
                    },
                    error: function (message) {
                        LG.showError(message);
                    }
                });
            }
            else {
                LG.tip('请选择行!');
            }
        }
        
        function confirmRow(){
          
            //var isSend = window.confirm("审核通过该信息吗？");
            //if (!isSend) return;
           
            var selected = grid.getSelected();        
            if (!selected) { LG.tip('请选择行'); return; }
              
            $.ligerDialog.confirm("审核通过该信息吗？" ,function (r) { if(r){
           
                    $.ajax({
                        url: 'approve/' + selected.id,
                        type: 'GET',                  
                        loading: '正在审核中...',                  
                        success: function () {
                            //LG.showSuccess('删除成功');
                            //detailWin.hide();                 
                            LG.tip('审核成功!');
                            f_reload();
                            app_reload();
                        },
                        error: function (message) {
                            LG.showError(message);
                        }
                    })}
                else      
                    return} );              
            }  
       
            function multiRow(){
          
                //var isSend = window.confirm("审核通过该信息吗？");
                //if (!isSend) return;
                var selecteds="";
                var selRows = grid.getSelectedRows();    
                var len=selRows.length;
                if (len==0) { LG.tip('请选择行'); return; }           
                $.each(selRows, function (i){
                    selecteds=selecteds+selRows[i].id+",";
                });         
                $.ligerDialog.confirm("共有"+len+"条记录，审核通过这些信息吗？" ,function (r) { if(r){
           
                        $.ajax({
                            url: 'approvemulti?selecteds='+selecteds,
                            type: 'GET',                  
                            loading: '正在审核中...',                  
                            success: function () {
                                //LG.showSuccess('删除成功');
                                LG.tip('批量审核成功!');
                                f_reload();
                                app_reload();
                            },
                            error: function (message) {
                                LG.showError(message);
                            }
                        })}
                    else      
                        return} );              
                }  
                function cancelRow(){
                    var selected =   grid.getSelected();
                    if (!selected) { LG.tip('请选择行!'); return }      
                    showDetail({
                        id: selected.id
         
                    }, false);
                }      
	
        
                var detailWin_com = null, curentData_com = null, currentIsAddNew_com;
                var commentform = $("#commentform");	        
             
                function showDetail(data_com, isAddNew_com)
                {  
                    currentData_com = data_com;
                    currentIsAddNew_com = isAddNew_com;
                    if (detailWin_com)
                    {  
                        detailWin_com.show(); 
                    }
                    else
                    {  
                        //创建表单结构       
                        commentform.ligerForm({
                            inputWidth: 280,
                            fields: [
                                { name: "note.id", type: "hidden" },
                                { display: "审核意见", name: "comment", newline: true, 
                                    labelWidth: 100, width: 220, space: 30, type: "textarea" } 
                            ],
                            toJSON: JSON2.stringify
                        });

                        detailWin_com = $.ligerDialog.open({
                            target: $("#comment"),
                            width: 300, height: 200, top:80,
                            buttons: [
                                { text: '确定', onclick: function () { save(); } },
                                { text: '取消', onclick: function () { detailWin_com.hide(); } }
                            ]
                        });
                    }
          
                    if (currentData_com)
                    {   
                        $("[name$=id]").val(currentData_com.id)     	          
                        $("[name$=comment]").focus();
                    }
       
                    function save()
                    {
                        $("#commentform").validate();
             
                        $.ajax({
                            loading: '正在保存数据中...',
                            type: 'POST',
                            url: 'approvefail',                  
                            data: $("#commentform").serialize(),
                            success: function ()
                            {
                                detailWin_com.hide();
                                grid.loadData();             
                                LG.tip('退回成功!');
                            },
                            error: function (message)
                            {
                                LG.tip(message);
                            }
                        });
                    }
                }
              
              
                var detailWin = null, currentData = null, currentIsAddNew;
                var mainform = $("#mainform");
                function showDetailWindow(data, isAddNew)
                {
                    var mainform = $("#mainform");    
                    currentData = data;
                    //currentIsAddNew = isAddNew;
                    if (detailWin)
                    {     
                        detailWin.show(); 
                    }
                    else
                    {   
                        //创建表单结构           
                        mainform.ligerForm({
                            inputWidth: 500,
                            fields:
                                [  
                                { name: "note.id", type: "hidden" },
                                { name: "note.checkList.id", type: "hidden" },
                                { name: "note.approveLevel", type: "hidden" },
                                { name: "note.category", type: "hidden" },
                                { display: "考评项目", name: "checkListTitle", newline: true, 
                                    labelWidth: 120, width: 220, space: 30, type: "text"},
                                { display: "填报日期", name: "note.noteDate", newline: true,
                                    labelWidth: 120, width: 220, space: 30, type: "text", 
                                    validate: { required: true, maxlength: 50} }, 
                                { display: "姓名", name: "realName", newline: true,
                                    labelWidth: 120, width: 220, space: 30, type: "text"},    
                                { display: "科室", name: "deptName", newline: true,
                                    labelWidth: 120, width: 220, space: 30, type: "false"},    
                                { display: "内容", name: "note.content", newline: true,
                                    labelWidth: 120, width: 220, space: 30, type: "textarea" } ,
                                { display: "经办人(证明人)", name: "note.certifyMan", newline: true,
                                    labelWidth: 120, width: 220, space: 30, type: "text"}],        			
                            toJSON: JSON2.stringify
                        });
             
                        detailWin = $.ligerDialog.open({
                            target: $("#detail"), top:10,
                            //width: 300, height: 300, 
                            buttons: [
                                { text: '审核', onclick: function () { Approval(); } },
                                { text: '取消', onclick: function () { detailWin.hide(); } }
                            ]
                        });
                    }
          
                    if (currentData)
                    {  
                        $("[name$=id]").val(currentData.id)
                        $("#checkListTitle").val(currentData.checkListtitle);
                        $("[name$='checkList.id']").val(currentData.checkListId);
                        $("[name$=noteDate]").val(currentData.noteDate); 
                        $("[name$=realName]").val(currentData.realName);
                        $("[name$=deptName]").val(currentData.deptName);
                        $("[name$=content]").val(currentData.content);
                        $("[name$=certifyMan]").val(currentData.certifyMan);  
                        $("[name$=category]").val(currentData.category);
                        // $("[name$=content]").focus();
                    }
          
                    $("#checkListTitle").ligerGetTextBoxManager().setDisabled();
                    $("[name$=noteDate]").ligerGetTextBoxManager().setDisabled();
                    $("[name$=realName]").ligerGetTextBoxManager().setDisabled();
                    $("[name$=deptName]").ligerGetTextBoxManager().setDisabled();                                                   
                    $("[name$=certifyMan]").ligerGetTextBoxManager().setDisabled();
                    
                    $("[name$=content]").attr('readonly', 'readonly');
                    $("[name$=content]").addClass("l-text-disabled");
                   
                    function Approval(){
                        confirmRow();
                        detailWin.hide();
                    }            
                }
            })
            
            var level = ${level};
            var level2=level+1;
           
</script>
